package com.piggy.common.core.web.page;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.piggy.common.core.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 分页数据
 *
 * @author shark
 */
public class PageDomain {
    /**
     * 当前记录起始索引
     */
    private Integer pageNum;

    /**
     * 每页显示记录数
     */
    private Integer pageSize;

    private final List<OrderByItem> OrderByList = new ArrayList<>();

    public String getOrderBy() {
        if (CollUtil.isEmpty(OrderByList)) {
            return "";
        }
        return ArrayUtil.join(OrderByList.stream().map(OrderByItem::toString).toArray(), ",");
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void asc(String orderByColumn) {
        if (StrUtil.isNotBlank(orderByColumn)) {
            this.OrderByList.add(OrderByItem.asc(orderByColumn));
        }
    }

    public void desc(String orderByColumn) {
        if (StrUtil.isNotBlank(orderByColumn)) {
            this.OrderByList.add(OrderByItem.desc(orderByColumn));
        }
    }

}
